

import Home from '../views/Admin/Home';
import Dept from '../views/Admin/Dept';
import User from '../views/Admin/User';
import Role from '../views/Admin/Role';
import NotFound from '../views/Admin/NotFound';


// 所有路由配置的数组

const allRoutes:any[] = [
    {
        "key":"0-0",
        path:'/Admin/Home',
        component:Home
    },
    {
        "key":"0-1-0",
        path:'/Admin/Dept',
        component:Dept
    },
    {
        "key":"0-1-1",
        path:'/Admin/User',
        component:User
    },
    {
        "key":"0-1-2",
        path:'/Admin/Role',
        component:Role
    }
]


// 定义一个当前用户的路由配置

export const gettCurrentRoutes=()=>{

    // 1、获取当前用户的权限
    const checkedKeys = JSON.parse(sessionStorage.getItem("checkedKeys") as string);

    // 2、根据当前用户的权限得到当前用户的路由配置。
    const currentRoutes:any[]=[];
    allRoutes.forEach(item=>{
        if(checkedKeys.includes(item.key)){
            currentRoutes.push({...item});
        }
    })

    console.log("currentRoutes",currentRoutes);

    currentRoutes.push({
        component:NotFound
    });
    
    return currentRoutes;
}